package com.ruoyi;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.json.JSONUtil;


import java.util.Map;


@Slf4j
@Component
@Order(1)
@RequiredArgsConstructor
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class CommandLineInitResource implements CommandLineRunner
{
    /**
     * 上下文
     */
    @Autowired
    WebApplicationContext applicationContext;



    @Override
    public void run(String... args) throws Exception {

        //获取使用RestController注解标注的的所有controller类
        Map<String, Object> controllers = applicationContext.getBeansWithAnnotation(RestController.class);
        //遍历每个controller层
        for (Map.Entry<String, Object> entry : controllers.entrySet()) {
            Object value = entry.getValue();
            System.out.println("拿到controller："+entry.getKey()+"，拿到value："+value);
            Class<?> aClass = AopUtils.getTargetClass(value);
            System.out.println("拿到Class:"+aClass);
            log.info("所有方法:"+ JSONUtil.toJsonStr(aClass.getDeclaredMethods()));
        }

    }

}
